home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
DBL Pascal Library
/
INIT Shell Folder
/
INIT Example ƒ
/
ChangedResPatch.p
< prev
next >
Wrap
Text File
|
1990-05-28
|
2KB
|
60 lines
unit INITShellResident;
{Copyright © 1990, David B. Lamkins}
{All rights reserved.}
{This unit must be compiled as a separate project, since code resource projects cannot have}
{multiple segments. We need this to be in a separate segment from the INIT loader since we}
{depend upon the presence of a the standard code header as a place to stash a handle to any}
{globals we may need for the patch. Also, it is much easier and safer to size and detach a}
{separate resource for the patch code than it is to play games with address arithmetic and}
{call _BlockMove to make a copy of the patch code. By convention this code resource will}
{have a type of 'IRES' (see INITShellLoader).}
interface
uses
INITShellGlobals, INITShellInlines, Retrace, SysEqu, ResCheck;
procedure main;
implementation
{$D-}
{$V-}
{$R-}
{This is the resident code. It may have local variables. Global data must be accessed through}
{the handle obtained from the GlobalsHandle function. See the INITShellInlines unit for further}
{programming details.}
procedure main;
{Patch for ChangedResource(h: Handle);}
{Patch ChangedResource to inhibit all changes to resources which may contain a virus.}
{Note that this is not foolproof, since the application may not detect the signalled error}
{and may end up writing the changed resource anyway.}
type
IntPtr = ^INTEGER;
var
theID: INTEGER;
theType: ResType;
theName: Str255;
theSize: LONGINT;
theHandleArg: Handle;
begin
Break; {debug stop, depending upon compile-time variable Debugging}
{First, we need to pull the handle argument to ChangedResource off the stack.}
theHandleArg := Handle(LParam(0));
{Now we find out all about the resource, so we can censor if needed.}
GetResInfo(theHandleArg, theID, theType, theName);
{Now we test the resource attributes, and perhaps its contents, looking for trouble.}
if DangerousResource(theType, theID, @theName, theHandleArg) then
begin {we found it - fake an error and skip out w/o executing the trap}
IntPtr(ResErr)^ := fLckdErr;
SysBeep(5);
DeallocateAndReturn(SIZEOF(Handle));
end
else {no problem, continue with the trap as soon as we exit.}
SetTrapExit;
end;
end.